<!-- eslint-disable @typescript-eslint/no-explicit-any -->
<template>
  <div>
    <span style="text-align: center; font-size: 20px; font-weight: 600"
    >添加权限</span
  >
  <div>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="权限编号">
        <el-input v-model="form.permissionCoding" readonly="true" />
      </el-form-item>

      <el-form-item label="请输入权限名称">
        <el-input v-model="form.permissionName" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="AddPermission">添加</el-button>
        <el-button @click="ent">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, onMounted } from "vue";
import axios from "axios";
// import { useRouter } from "vue-router";
// const router = useRouter();
import { ElMessage } from "element-plus";
const apiurlAdd = import.meta.env.VITE_APP_API_URL_RBACAdd;
//权限添加的form
const form = reactive({
  permissionId: 0,
  permissionCoding: "",
  permissionName: "",
  permissionState: true, //是否启用
  isDelete: false, //是否删除
  url: "无",
  handle: "MaxAdmin",
  handleContext: "添加角色信息",
  handleTime: new Date(),
  pid: 1,
});
//取消
const ent = () => {
  form.permissionName = "";
  form.permissionCoding = new Date()
    .toString()
    .substring(7, 25)
    .replace(" ", "")
    .replace(" ", "")
    .replace(" ", "")
    .replace(":", "")
    .replace(":", "")+ Math.floor(Math.random() * 100);
    form.permissionCoding = form.permissionCoding.replace(" ", "");
};
//添加权限

const AddPermission = () => {
  if (form.permissionName == "") {
    ElMessage.error("请输入权限名称");
    return;
  }
  console.log(apiurlAdd + "/api/RBAC/AddPermissionData");
  axios.post(apiurlAdd + "/api/RBAC/AddPermissionData", form).then((res: any) => {
    console.log(res.data);
    ElMessage.success(res.data.msg);
  });
};
//页面初始化
onMounted(() => {
  form.permissionCoding = new Date()
    .toString()
    .substring(7, 25)
    .replace(" ", "")
    .replace(" ", "")
    .replace(" ", "")
    .replace(":", "")
    .replace(":", "")+ Math.floor(Math.random() * 100);
    form.permissionCoding = form.permissionCoding.replace(" ", "");
});
</script>

<style scoped></style>
